package auctionhaus

class BidCreateService {

    def addBidOnListing(bidder, amount, listing) {

        def bidInstance = new Bid(bidder: bidder, bidDateTime: new Date(), amount: amount, listing: listing)
        if (!bidInstance.validate())
        {
            return bidInstance
        }

        listing.addToBids(bidInstance)
        listing.minimumBid = bidInstance.amount + 0.5f
        listing.save(flush: true)

        return bidInstance
    }
}
